<?php
error_reporting( E_ALL&~E_NOTICE );
ini_set( 'display_errors', 'off' );//屏蔽错误和警告提示
include("../mysql.php");
if(isset($_POST['name']) and isset($_POST['code']) and isset($_POST['adminpwd']))
{
if($_POST['adminpwd']!="dashen"){
    //echo "无权操作";
    exit;
}    
$name=$_POST['name'];
$code=$_POST['code'];



$check="SELECT * FROM `skills` WHERE `name` = '$name' AND `code` = '$code'";
$ret=mysql_query($check);
$row=mysql_fetch_array($ret);
if($row["code"]){
    echo "操作失败，已经有该条数据了";
    exit;
}
$check="SELECT * FROM `skills` WHERE `name` = '$name'";
$ret=mysql_query($check);
$row=mysql_fetch_array($ret);
if($row["code"]){
    $old_code=$row["code"];
    if($code!=$old_code){
        $mysql="UPDATE `skills` SET `code` = '$code' WHERE `name` ='$name' and `code` ='$old_code';";
        mysql_query($mysql);
    }
    exit;
}
$sql="alter table `skills` AUTO_INCREMENT=1";
mysql_query($sql);  //序列号自动归1
$mysql="INSERT INTO `skills` (`id`, `name`, `code`) VALUES (NULL, '$name', '$code');";
mysql_query($mysql);
echo "新增成功一条数据为:[$name,$code]";
}
else{
    echo "无权访问";
}
?>